package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.CarBrand;
import com.zygh.interactiveplatform.module.service.CarBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-01-29
 */
@RestController
@RequestMapping("/car-brand")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_CARBRAND})
public class CarBrandController {
    @Resource
    private CarBrandService carBrandService;

    @ApiOperation(value = "厂商新增", notes = "厂商新增")
    @PostMapping("addCarBrande")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_CARBRAND, content = "厂商新增")
    public ResponseDTO addCarBrande(@RequestBody @Valid CarBrand carBrand) {
        return carBrandService.addCarBrand(carBrand);
    }
    @ApiOperation(value = "厂商修改", notes = "厂商修改")
    @PostMapping("updateCarBrand")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_CARBRAND, content = "厂商修改")
    public ResponseDTO updateCarBrand(@RequestBody @Valid CarBrand carBrand) {
        return carBrandService.updateCarBrand(carBrand);
    }
    @ApiOperation(value = "厂商删除", notes = "厂商删除")
    @PostMapping("deleteCarBrand")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_CARBRAND, content = "厂商删除")
    public ResponseDTO deleteCarBrand(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return carBrandService.deleteCarBrand(new_id);
    }
    @ApiOperation(value = "查询所有厂商", notes = "查询所有厂商")
    @GetMapping("findCarBrandAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_CARBRAND, content = "查询所有厂商")
    public ResponseDTO findCarBrandAll(Integer current, Integer size) {
        return carBrandService.findCarBrandAll(current,size);
    }

}
